package com.onurokan.someone4me.photo.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

import org.springframework.web.multipart.MultipartFile;

import com.onurokan.someone4me.user.domain.User;

@Entity
@Table(name = "photo")
public class Photo implements Serializable, Comparable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static final int IMAGE_WIDTH = 600;
	public static final int IMAGE_HEIGHT = 600;
	public  static final int MAX_NUM_PHOTO = 10;
	private String caption;
	private MultipartFile file;
	private double height;
	private long id;
	private int rank;
	private double width;
	private double x;
	private double y;
	private User user;

    @ManyToOne
    @JoinColumn(name="user_id",insertable=false, updatable=false)
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id", unique = true, nullable = false)
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}
	
	@Column(name = "caption")
	public String getCaption() {
		return caption;
	}

	@Transient
	public MultipartFile getFile() {
		return file;
	}

	@Column(name = "height")
	public double getHeight() {
		return height;
	}

	@Column(name = "rank")
	public int getRank() {
		return rank;
	}

	@Column(name = "width")
	public double getWidth() {
		return width;
	}

	@Column(name = "x")
	public double getX() {
		return x;
	}

	@Column(name = "y")
	public double getY() {
		return y;
	}

	public void setCaption(String caption) {
		this.caption = caption;
	}

	public void setFile(MultipartFile file) {
		this.file = file;
	}

	public void setHeight(double height) {
		this.height = height;
	}

	public void setPhotoId(long id) {
		this.id = id;
	}

	public void setRank(int order) {
		this.rank = order;
	}

	public void setWidth(double width) {
		this.width = width;
	}

	public void setX(double x) {
		this.x = x;
	}

	public void setY(double y) {
		this.y = y;
	}

	public int compareTo(Object obj) {
		Photo rhs = (Photo)obj;
		return rhs.getRank() - this.getRank();
	}
}
